# -*- coding:utf-8 -*-
# 快速排序

def quicksort(array):
    if len(array) < 2:
        return array
    else:
        pivot = array[0]
        less = [i for i in array[1:] if i <= pivot]
        greater = [i for i in array[1:] if i > pivot]
        return quicksort(less) + [pivot] + quicksort(greater)

def quick(list):
    if len(list) < 2:
        return list
    else:
        left = i = 0
        j = len(list) - 1
        
        while i != j:
            while list[j] >= list[left] and i < j:
                j -= 1
            while list[i] <= list[left] and i < j:
                i += 1
            
            if i < j:
                list[i], list[j] = list[j], list[i]
        list[i], list[left] = list[left],  list[i]
        return quick(list[left:i]) + [list[i]] + quick(list[i+1:])



list = [54, 26, 93, 17, 77, 31, 44, 55, 20]
print(quick(list))